package cn.xshi.bpm.web;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

import cn.xshi.bpm.service.LcFormFieldService;
import io.swagger.annotations.Api;
import cn.xshi.common.annotation.Auth;
import cn.xshi.common.base.BasePage;
import cn.xshi.common.base.BaseResult;
import cn.xshi.common.entity.OauthAccountEntity;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.*;
import cn.xshi.common.util.StringUtil;
import io.swagger.annotations.ApiOperation;
import com.github.pagehelper.PageInfo;
import cn.xshi.common.base.BaseAction;
import cn.xshi.common.base.BaseSearch;
import cn.xshi.bpm.model.LcFormField;

import javax.annotation.Resource;
/**
 * @Desc 工作流表单字段
 * @Author 邓纯杰
 * @CreateTime 2022-04-04 19:17:12
 */
@Api(value = "工作流表单字段", description = "工作流表单字段", tags = "工作流表单字段")
@RestController
@RequestMapping("/lcFormField")
public class LcFormFieldController extends BaseAction{

	@Resource
	private LcFormFieldService lcFormFieldService;

	/**
	 * 查询并分页
	 * @param baseSearch
	 */
	@ApiOperation(value="查询并分页", notes="查询并分页")
	@Auth(value = "/lcFormField/list",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@PostMapping(value="/list")
	public BasePage<List<LcFormField>> getLcFormFieldListByCondition(@RequestBody(required=true)BaseSearch baseSearch){
		Map<String, Object> condition = baseSearch.convert();
		commonHPager(baseSearch);
		List<LcFormField> lcFormFieldList = lcFormFieldService.getLcFormFieldListByCondition(condition);
		for(LcFormField lcFormField:lcFormFieldList){
			if(!StringUtil.isEmpty(lcFormField.getCreateId())){
				OauthAccountEntity createBy = getAccount(lcFormField.getCreateId());
				if(null != createBy){
					lcFormField.setCreateBy(createBy.getName());
				}
			}
			if(!StringUtil.isEmpty(lcFormField.getUpdateId())){
				OauthAccountEntity modifieBy = getAccount(lcFormField.getUpdateId());
				if(null != modifieBy){
					lcFormField.setModifiedBy(modifieBy.getName());
				}
			}
		}
		PageInfo<LcFormField> page = new PageInfo<LcFormField>(lcFormFieldList);
		return outPageBootStr(page,baseSearch);
	}

	/**
	 * 查询单条记录
	 * @param id
	 */
	@ApiOperation(value="查询单条记录", notes="查询单条记录")
	@Auth(value = "/lcFormField/get",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@GetMapping(value="/get/{id}")
	public BaseResult<LcFormField> getLcFormFieldById(@PathVariable("id")String id){
		LcFormField lcFormField = lcFormFieldService.getLcFormFieldById(id);
		OauthAccountEntity createBy = getAccount(lcFormField.getCreateId());
		if(null != createBy){
			lcFormField.setCreateBy(createBy.getName());
		}
		if(!StringUtil.isEmpty(lcFormField.getUpdateId())){
			OauthAccountEntity modifiedBy = getAccount(lcFormField.getUpdateId());
			if(null != modifiedBy){
				lcFormField.setModifiedBy(modifiedBy.getName());
			}
		}
		return outDataStr(lcFormField);
	}

	/**
	 * 添加
	 * @param lcFormField
	 */
	@ApiOperation(value="添加", notes="添加")
	@PostMapping(value="/add")
	public BaseResult addLcFormField(@RequestBody LcFormField lcFormField){
		int i = 0;
		if(null != lcFormField){
			i=lcFormFieldService.addLcFormField(lcFormField);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 修改
	 * @param lcFormField
	 */
	@ApiOperation(value="修改", notes="修改")
	@PutMapping(value="/update")
	public BaseResult updateLcFormField(@RequestBody LcFormField lcFormField){
		int i = 0;
		if(null != lcFormField){
			i=lcFormFieldService.updateLcFormField(lcFormField);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 删除
	 * @param id
	 */
	@ApiOperation(value="删除", notes="删除")
	@DeleteMapping(value="/delete")
	public BaseResult delLcFormField(String id){
		int i = 0;
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<String, Object>();
			condition.put("id",id.split(","));
			i=lcFormFieldService.delLcFormField(condition);
		}
		if(i>0){
			return outAudStr(true);
		}else{
			return outAudStr(false);
		}
	}

	/**
	 * 查询集合
	 * @param id
	 */
	@ApiOperation(value="查询集合", notes="查询集合")
	@Auth(value = "/lcFormField/find",authenticationType = Auth.AuthorizationType.REQUIRED_LOGIN_NOT_AUTH)
	@GetMapping(value="/find")
	public BaseResult<List<LcFormField>> find(String id){
		if(!StringUtil.isEmpty(id)){
			Map<String, Object> condition = new HashMap<>();
			condition.put("id",id.split(","));
			List<LcFormField> lcFormFieldList = lcFormFieldService.getLcFormFieldListByCondition(condition);
			return new BaseResult(lcFormFieldList);
		}
		return new BaseResult();
	}

}
